home *** CD-ROM | disk | FTP | other *** search
- -> handle args from both WB and CLI using only a ReadArgs() template
- -> that is, allow parse tooltypes with shell template
- -> Used in ShellScr by Kyzer/CSG
-
- ->example:
- -> IF rdargs := readargs('CX_PRIORITY/N, CX_POPKEY, CX_POPUP/S',
- -> args:=NEW [0,0,0], wbmessage)
- ->
- -> cx_pri := IF args[0] THEN Long(args[0]) ELSE 0
- -> hotkey := IF args[1] THEN args[1] ELSE 'ctrl alt del'
- -> popup := args[2]
- -> [....]
- -> FreeArgs(rdargs)
- -> ENDIF
-
- -> FIXES:
- -> - (06.04.98) Gags when directories are selected. Fixed.
-
- -> TODO:
- -> - support =YES and =NO tooltypes in switches
- -> - special case (list of icon names) to /M switched variables
-
- OPT MODULE
-
- MODULE 'icon', 'dos/rdargs', 'workbench/startup', 'workbench/workbench'
-
- -> Basically, we run through all the selected icons' tooltypes from
- -> first (our own icon) to last. if the left part of a tooltype
- -> (in 'BLA=FISH', the left part is 'BLA') is judged by DOS to be
- -> a keyword from the template (this includes parsing aliases for
- -> keywords) then we insert it and its right part (if there is one)
- -> into a list in the appropriate place, which can overwrite tooltypes
- -> already there (eg, selected icons override default settings in our
- -> own icon). Once we have this list of keywords and values, we can make
- -> a single string with all these keywords and values, and give it to
- -> ReadArgs.
-
- -> The code that splits a tooltype into left and right parts is clever
- -> enough to ignore 'disabled' tooltypes which begin with '(', and also
- -> ignores tooltypes beginning IM1= or IM2= for performance reasons (NewIcons
- -> contain a lot of these tooltypes for their icon data)
-
- EXPORT PROC readargs(template:PTR TO CHAR, args, wbmsg:PTR TO wbstartup) HANDLE
- DEF rdargs=NIL, tooltype, name, val, m, n, arg, len, dir,
- arglst=NIL:PTR TO LONG, -> a list to all our args and their values
- dobj=NIL:PTR TO diskobject, -> diskobject of 'current icon'
- tooltypes:PTR TO LONG -> tooltypes of 'current icon'
-
- -> If we were run from shell, then just parse as normal
- IF wbmsg=NIL THEN RETURN ReadArgs(template, args, NIL)
-
- -> make sure icon.library is available
- IF (iconbase := OpenLibrary('icon.library', 36))=NIL THEN Raise("LIB")
-
- -> make a big enough list to hold all name/value pairs for template
- len:=1; n := template; WHILE m := n[]++ DO IF m="," THEN INC len
- IF (arglst := List(len*2))=NIL THEN Raise("MEM")
- SetList(arglst, ListMax(arglst))
-
- -> Go through all tooltypes in all selected icons
- FOR m := 0 TO wbmsg.numargs-1
- dir := CurrentDir(wbmsg.arglist[m].lock)
- dobj := GetDiskObject(wbmsg.arglist[m].name)
- CurrentDir(dir)
-
- IF dobj
- IF tooltypes := dobj.tooltypes
- WHILE tooltype := tooltypes[]++
- -> split up tooltype
- name, val := ttsplit(tooltype)
- -> if in template, place into appropriate list entry
- IF (arg:=FindArg(template, name))<>-1
- n := arg*2
- IF arglst[ n ] THEN DisposeLink(arglst[ n ])
- IF arglst[n+1] THEN DisposeLink(arglst[n+1])
- arglst[ n ] := name
- arglst[n+1] := val
- ELSE
- DisposeLink(name)
- DisposeLink(val)
- ENDIF
- ENDWHILE
- ENDIF
- FreeDiskObject(dobj); dobj:=NIL
- ENDIF
- ENDFOR
-
- -> calculate length of final 'arg string' to be parsed by ReadArgs()
- len := 0
- FOR n := 0 TO ListLen(arglst)-1
- IF arg:=arglst[n] THEN len := len + 3 + EstrLen(arg)
- ENDFOR
-
- IF (m := String(len))=NIL THEN Raise("MEM")
- StrCopy(m, '')
-
- -> concatenate final arg settings into one big string
- FOR n:=0 TO ListLen(arglst)-1
- IF arg := arglst[n]
- -> append either 'arg ' or '"arg" ' if arg has spaces in it
- IF InStr(arg, ' ')=-1
- StrAdd(m, arg)
- StrAdd(m, ' ')
- ELSE
- StrAdd(m, '"')
- StrAdd(m, arg)
- StrAdd(m, '" ')
- ENDIF
- ENDIF
- ENDFOR
-
- -> perform the ReadArgs call on our constructed string
- rdargs := ReadArgs(template, args,
- [m, EstrLen(m), 0, NIL, NIL, 0, NIL, RDAF_NOPROMPT]:LONG
- )
-
- -> throw away big string
- DisposeLink(m)
-
- EXCEPT DO
- IF arglst
- FOR n := 0 TO ListLen(arglst) DO IF arg:=arglst[n] THEN DisposeLink(arg)
- DisposeLink(arglst)
- ENDIF
-
- IF dobj THEN FreeDiskObject(dobj)
- IF iconbase THEN CloseLibrary(iconbase)
-
- ReThrow()
- ENDPROC rdargs
-
- PROC ttsplit(s:PTR TO CHAR)
- -> of something 'blah=foo', returns 'blah','foo'
- -> of something 'blah', returns 'blah',NIL
- -> of something beginning '(', 'IM1=' or 'IM2=', returns NIL,NIL
-
- DEF div, len, l, r
-
- IF s=NIL THEN RETURN NIL, NIL
- IF (s[]="(") OR StrCmp(s, 'IM1=', 4) OR StrCmp(s, 'IM2=', 4) THEN
- RETURN NIL, NIL
-
- len := StrLen(s)
- div := InStr(s, '=')
-
- IF div=-1
- l := String(len)
- IF l THEN StrCopy(l, s)
- RETURN l, NIL
- ENDIF
-
- l := String(div+1)
- r := String(len-div)
-
- IF (l AND r)=NIL
- IF l THEN DisposeLink(l)
- IF r THEN DisposeLink(r)
- RETURN NIL, NIL
- ENDIF
-
- MidStr(l, s, 0, div)
- MidStr(r, s, div+1)
- ENDPROC l, r
-